<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/
Route::get('/', function(){
	return View::make('frontend.index');
});

Route::get("/{view}", function($view){
    return View::make('frontend.'.$view);
});

/*
Route::get('/creategroup', function()
{
	try
	{
	    // Create the group
	    $group = Sentry::createGroup(array(
	        'name'        => 'superusers',
	        'permissions' => array(
	            'read' => 1,
	            'write' => 1,
	        ),
	    ));

	    echo "superusers Group is created";
	}
	catch (Cartalyst\Sentry\Groups\NameRequiredException $e)
	{
	    echo 'Name field is required';
	}
	catch (Cartalyst\Sentry\Groups\GroupExistsException $e)
	{
	    echo 'Group already exists';
	}

});


Route::get('/checkgroup', function()
{

	try
	{
	    $group = Sentry::findGroupByName('superusers');
	    echo "superusers Group Exists";
	}
	catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e)
	{
	    echo 'Group was not found.';
	}

});


Route::get('/createadminuser', function()
{

	try
	{

	    // Find the group using the group name
	    $adminGroup = Sentry::findGroupByName("superusers");

	    // Create the user
	    $user = Sentry::createUser(array(
	        'email'    => 'admin@greentomato.com.ar',
	        'password' => 'test123',
			'activated'   => true,
	    ));

	    echo "Admin user is created<br>";


	    // Assign the group to the user
	    $user->addGroup($adminGroup);

	    echo "Admin user assigned to administration group";
	}
	catch (Cartalyst\Sentry\Users\PasswordRequiredException $e)
	{
	    echo 'Password field is required.';
	}
	catch (Cartalyst\Sentry\Users\UserExistsException $e)
	{
	    echo 'User with this login already exists.';
	}
	catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e)
	{
	    echo 'Group was not found.';
	}

});
*/

Route::get('admin/login', array('as' => 'adminlogin', 'uses' => 'App\Controllers\Admin\AuthController@getLogin'));
Route::get('admin/logout', array('as' => 'adminlogout', 'uses' => 'App\Controllers\Admin\AuthController@logout'));
Route::post('admin/login', array('as' => 'adminlogin', 'uses' => 'App\Controllers\Admin\AuthController@postLogin'));

Route::group(array('prefix' => 'admin', 'before' => 'administrationauth'), function() {

	Route::any('/', 'App\Controllers\Admin\AuthController@getIndex');

    Route::resource('dashboard', 'App\Controllers\Admin\DashboardController');
    Route::controller('dashboard', 'App\Controllers\Admin\DashboardController');

    Route::resource('contents/categories', 'App\Controllers\Admin\CategoriesController');
    Route::controller('contents/categories', 'App\Controllers\Admin\CategoriesController');
               
    Route::resource('contents', 'App\Controllers\Admin\ContentsController');
    Route::controller('contents', 'App\Controllers\Admin\ContentsController');

    Route::resource('gallery', 'App\Controllers\Admin\GalleryController');
    Route::controller('gallery', 'App\Controllers\Admin\GalleryController');
                
    Route::resource('users', 'App\Controllers\Admin\UsersController');
    Route::controller('users', 'App\Controllers\Admin\UsersController');
});

